package com.srpngfox.demo.controller;

import com.srpngfox.demo.domain.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@Api(value = "学生系统")
@RequestMapping("/student")
@RestController
public class UserController {

    @PostMapping("/create")
    @ApiOperation(value = "添加学生")
    public User create (@Valid User user) {
        return user;
    }

    @GetMapping("/list")
    @ApiOperation(value = "学生列表")
    public List<User> listUser (@ApiParam("查看第几页") @RequestParam int pageIndex,
                                @ApiParam("每页多少条") @RequestParam int pageSize) {
        List<User> result = new ArrayList<>();
        result.add(new User(1L,"aaa", 50, "北京", "aaa@ccc.com"));
        result.add(new User(2L,"bbb", 21, "广州", "aaa@ddd.com"));
        return result;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "添加学生")
    public User UserById (@Valid Long id) {
        return new User(1L,"bbb", 21, "上海", "aaa@bbb.com");
    }

    @ApiIgnore
    @DeleteMapping("{id}")
    public String deleteUser (@Valid Long id) {
        return "delete user : " + id;
    }
}
